package com.itheima;


import com.itheima.config.SpringConfig;
import com.itheima.dao.BookDao;
import com.itheima.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App2 {

    public static void main(String[] args) {
////        通过配置文件获取容器
//        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//
////        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
////        System.out.println(bookDao);
//        BookService bookService = ctx.getBean(BookService.class);
//        System.out.println(bookService);

//        通过配置类获取容器
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        BookDao bookDao = (BookDao) ctx.getBean("bookDao");

        ctx.registerShutdownHook();

//        bookDao.save();
        System.out.println(bookDao);
        BookService bookService = ctx.getBean(BookService.class);
//        bookService.save();
        System.out.println(bookService);

//        ctx.close();
    }

}